package com.erqi.Controllers;

import com.erqi.dao.userDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author king
 * @Date 2020/7/20 13:39
 * @Version 1.0   用户的登录的操作方法
 */
@Controller
@Slf4j
public class UserController {

    @Autowired
    userDao PLcUserDao;

    @RequestMapping("/login")
    public String Login(String username , String password, String kt, HttpSession session, Model model, HttpServletResponse response) throws IOException {
        System.out.println("kt--------- = " + kt);
        int Ui = PLcUserDao.login(username,password,kt);
        System.out.println("user = " + Ui+"当前登录用户为："+username);
        if (Ui==0){
            response.sendRedirect("/plcUser");
            log.info("当前登录用户为：{}",username);
            return "login/login";
        }else if (Ui==3){
            model.addAttribute("loginMsg","密码错误");
            model.addAttribute("kt",kt);
            return "login/login";
        }else if (Ui==6){
            model.addAttribute("loginMsg","没有标识码重新去登录");
            model.addAttribute("kt",kt);
            return "plc/plcDataList";
        }else {
            model.addAttribute("loginMsg","账号密码错误");
            model.addAttribute("kt",kt);
            return "login/login";
        }
    }
}
